//
//  DCPersonIDCardViewController.m
//  JiuyaoDriver
//
//  Created by 大橙子 on 2018/11/29.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCPersonIDCardViewController.h"
#import "DCIDCardImagePicker.h"
@interface DCPersonIDCardViewController ()<TZImagePickerControllerDelegate>
//@property (nonatomic,strong) UIImageView *imageView;
@end

@implementation DCPersonIDCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"资料认证";
    [self setUpMainUI];
}
-(void)setUpMainUI {

    UIView *nameView = [self getViewWithFrame:CGRectMake(10, 10, self.view.width - 20, 40) Title:@"姓名:" placeholder:@"录入姓名需与身份证姓名一致" subText:@""];
    [self.view addSubview:nameView];
    
    UIView *IDcardView = [self getViewWithFrame:CGRectMake(10, nameView.bottom, self.view.width - 20, 40) Title:@"身份证:" placeholder:@"录入姓名需与身份证姓名一致" subText:@""];
    [self.view addSubview:IDcardView];
    
//    NSArray *titleArr = @[@"身份证",@"身份证",@"驾驶证",@"驾驶证"];
//    NSArray *subTitleArr = @[@"正面",@"反面",@"正本",@"副本"];
    CGFloat kMargin = 13;
    CGFloat btnW = (self.view.width - kMargin*3)/2;
    CGFloat btnH = 130*HEIGHTSCALE6;
    __weak typeof(self) weakself = self;
    
    DCIDCardImagePicker *firstImageView = [[DCIDCardImagePicker alloc]initWithFrame:CGRectMake(kMargin, IDcardView.bottom+20+kMargin, btnW, btnH)];
    firstImageView.titleLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:@"身份证(正面)" subStringColor:[UIColor blackColor] subString:@"身份证" andFont:FONT(16)];
    firstImageView.block = ^(UIImageView * _Nonnull imageView) {
        
        TZImagePickerController *imageVC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        [imageVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            imageView.image = photos[0];
        }];
        [weakself presentViewController:imageVC animated:YES completion:nil];
    };
    [self.view addSubview:firstImageView];
    
    DCIDCardImagePicker *secondImageView = [[DCIDCardImagePicker alloc]initWithFrame:CGRectMake(kMargin+firstImageView.right, firstImageView.y, btnW, btnH)];
    secondImageView.titleLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:@"身份证(反面)" subStringColor:[UIColor blackColor] subString:@"身份证" andFont:FONT(16)];
    secondImageView.block = ^(UIImageView * _Nonnull imageView) {
        
        TZImagePickerController *imageVC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        [imageVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            imageView.image = photos[0];
        }];
        [weakself presentViewController:imageVC animated:YES completion:nil];
    };
    [self.view addSubview:secondImageView];
    
    DCIDCardImagePicker *thirdImageView = [[DCIDCardImagePicker alloc]initWithFrame:CGRectMake((self.view.width - btnW)/2, firstImageView.bottom+kMargin, btnW, btnH)];
    thirdImageView.titleLabel.attributedText = [YLAttributedStr changeSubStringWithTotalString:@"营业执照" subStringColor:[UIColor blackColor] subString:@"营业执照" andFont:FONT(16)];
    thirdImageView.block = ^(UIImageView * _Nonnull imageView) {
        TZImagePickerController *imageVC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
        [imageVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            imageView.image = photos[0];
        }];
        [weakself presentViewController:imageVC animated:YES completion:nil];
        
    };
    [self.view addSubview:thirdImageView];

    
    UIButton * surtBtn = [[UIButton alloc]init];
    [surtBtn setTitle:@"提交" forState:UIControlStateNormal];
    surtBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [surtBtn addTarget:self action:@selector(surtBtnOnClicked) forControlEvents:UIControlEventTouchUpInside];
    surtBtn.layer.cornerRadius = 20;
    surtBtn.layer.masksToBounds = YES;
    surtBtn.backgroundColor = BlueColor;
    [self.view addSubview:surtBtn];
    [surtBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_offset(40);
        make.left.equalTo(weakself.view.mas_left).offset(40);
        make.right.equalTo(weakself.view.mas_right).offset(-40);
        make.top.equalTo(thirdImageView.mas_bottom).offset(30);
    }];
}

-(void)surtBtnOnClicked {
    DCLogFunc;
}
-(UIView *)getViewWithFrame:(CGRect)frame Title:(NSString *)title placeholder:(NSString *)placeholder subText:(NSString *)subText {
    UIView *view = [[UIView alloc]initWithFrame:frame];
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80*WIDTHSCALE6, view.height)];
    nameLabel.text = title;
//    nameLabel.backgroundColor = RandomColor;
    [view addSubview:nameLabel];
    
    UITextField *nameField = [[UITextField alloc]initWithFrame:CGRectMake(nameLabel.right, 0, view.width - nameLabel.width, view.height)];
    nameField.placeholder = placeholder;
    nameField.text = subText;
    [view addSubview:nameField];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(nameLabel.right, nameField.bottom, nameField.width, 0.5)];
    line.backgroundColor = [UIColor lightGrayColor];
    [view addSubview:line];
    
    return view;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
